<template>
	<view class="pages">
		<!-- 这里是状态栏 -->
		<view class="status_bar"></view>
		<view class="title">登录 <text class='right' @click="gopage('/pages/login/register1')">注册 &gt;</text></view>
		<view class="content">
			<view class="input_row">
				<image src="../../static/cut/people.png" mode=""></image>
				<input type="text" v-model="account" placeholder="请输入账号或手机号"/>
			</view>
			<view class="input_row">
				<image src="../../static/cut/lock.png" mode=""></image>
				<input type="text" v-model="password" :password="paswIsShow" placeholder="请输入密码"/>
				<image class="showPassWord" @click="paswIsShowFun" v-if="paswIsShow" src="../../static/cut/paswhidde.png" mode=""></image>
				<image class="showPassWord" @click="paswIsShowFun" v-if="!paswIsShow" src="../../static/cut/paswShow.png" mode=""></image>
			</view>
			<view class="forget">
				 <checkbox-group @change="checkedboxchange">
					<checkbox style="transform: scale(0.7)" value="cb" checked="true" /><navigator url="tiaoli?setting=2" style="display:inline-block;color:#999;">同意安全环保隐私协议</navigator>
				</checkbox-group>
				<!-- <label class="radio">
					 <checkbox value="cb" style="transform: scale(0.7)" :checked="checkedbox" @click="checkedboxchange" /><navigator url="tiaoli?setting=2" style="display:inline-block;color:#999;">同意安全环保隐私协议</navigator>
				</label> -->
				<text @click="gopage('/pages/login/forget')">忘记密码？</text>
			</view>
			<image class="loginHT" src="../../static/cut/loginHT.png" mode=""></image>
			<button type="primary" class="btnLogin" @click="doLogin">登录</button>
			<view class="otherLogin">
				<view @click="weinxinlogin">
					<image src="../../static/cut/LoginWX.png" mode=""></image><text>微信一键登录</text>
				</view>
				<view @click="doLoginByQQ">
					<image src="../../static/cut/LoginQQ.png" mode=""></image><text>QQ一键登录</text>
				</view>
			</view>
		</view>
	</view>
	
	<!-- <navigator url="tiaoli?setting=2" style="text-align: center;color:#999;">隐私保管条例</navigator> -->
</template>

<script>
	import API from '../../common/api.js';
	export default {
		data() {
			return {
				account:'',
				// account:'17765371005',
				password:'',
				// password:'111111',
				paswIsShow:true,
				checkedbox:true,
			}
		},
		onShow() {
			// #ifdef APP-PLUS
			/* 隐藏凸起图标 */
			var icon = plus.nativeObj.View.getViewById("icon");
			if(icon){icon.hide();}
			// #endif
		},
		onLoad() {
			
		},
		methods: {
			//密码的显示隐藏
			paswIsShowFun(){
				this.paswIsShow = !this.paswIsShow
			},
			checkedboxchange(e){
				// this.checkedbox = !this.checkedbox
				// var items = this.items,
				this.checkedbox = e.detail.value.length==0?false:true;
			},
			doLogin(){
				if(!this.checkedbox){
					uni.showToast({
						title:'请同意协议',
						icon:"none"
					})
					return false
				}
				var _this = this;
				if(this.account&&this.password){
					uni.request({
						url:API.doLogin,
						data:{
							account:_this.account,
							password:_this.password,
						},
						method:"POST",
						header:API.get_head(),
						success: (res) => {
							if(res.data.code==0){
								uni.setStorageSync("userid",res.data.userid);
								uni.setStorageSync("deptid",res.data.deptid);
								uni.setStorageSync("vip_status",res.data.vipStatus);
								uni.setStorageSync("phone",_this.account);
								uni.setStorageSync("company",res.data.company);
								// _this.findCompanyInfo(res.data.userid);
								uni.switchTab({
									url:'/pages/newpages/home'
								})
							}else{
								uni.showToast({
									title:res.data.message,
									icon:"none"
								})
							}
						},
						fail: () => {
							uni.showToast({
								title:"加载失败",
								icon:'none'
							})
						}
					})
				}else{
					uni.showToast({
						title:"请填写账户密码",
						icon:"none"
					})
				}
			},
			findCompanyInfo(id){//查询企业信息验证是否第一次登陆
				var _this = this;
				uni.request({
					url:API.findCompanyInfo,
					data:{
						type:2,
						userId:id,
					},
					method:"POST",
					header:API.get_head(),
					success: (res) => {
						uni.setStorageSync('companyInfo', res.data);
						if(res.data==null||!res.data.faren||!res.data.faren||!res.data.tel||!res.data.address){
							// uni.showModal({
							// 	content: '您未绑定企业是否绑定？',
							// 	showCancel: true,
							// 	success: res => {
							// 		if(res.confirm){
							// 			uni.navigateTo({
							// 				url:"register2"
							// 			})
							// 		}
							// 	},
							// 	fail: () => {},
							// 	complete: () => {}
							// });
						}else{
							uni.switchTab({
								url:'/pages/newpages/home'
							})
						}
						
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			gopage(url){
				uni.navigateTo({
					url:url
				})
			},
			doLoginByQQ(){
				// #ifdef APP-PLUS
					var _this =this;
					uni.login({
					  provider: 'qq',
					  success: function (loginRes) {
						// 获取用户信息
						uni.getUserInfo({
						  provider: 'qq',
						  success: function (infoRes) {
							_this.autoLogin(
									infoRes,
									API.wxLogin,
									{
										openid:infoRes.userInfo.openId,
										nickname:infoRes.userInfo.nickname,
										avatar:infoRes.userInfo.figureurl_qq_2,
									}
							)
						  }
						});
					  }
					});
				// #endif
			},
			weinxinlogin(){//微信登陆
				// #ifdef APP-PLUS
					var _this =this;
					uni.login({
					  provider: 'weixin',
					  success: function (loginRes) {
						// 获取用户信息
						uni.getUserInfo({
						  provider: 'weixin',
						  success: function (infoRes) {
							_this.autoLogin(
									infoRes,
									API.wxLogin,
									{
										openid:infoRes.userInfo.openId,
										nickname:infoRes.userInfo.nickName,
										avatar:infoRes.userInfo.avatarUrl,
									}
							)
						  }
						});
					  }
					});
				// #endif
			},
			autoLogin(infoRes,url,data){
				uni.request({
					url:url,
					method:"POST",
					data:data,	
					header:API.get_head(),
					success: (res) => {
						if(res.data.code==0){
							if(!res.data.data.isTel){
								uni.showModal({
									content:res.data.data.message,
									showCancel: false,
									success: res => {
										uni.navigateTo({
											url: 'register1?openid='+infoRes.userInfo.openId,
										});
									}
								});
							}else{
								_this.findCompanyInfo()
							}
							uni.setStorageSync("userid",res.data.userid);
							uni.setStorageSync("deptid",res.data.deptid);
						}else{
							uni.showToast({
								title:"登录失败",
								icon:'none'
							})
						}
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			}
		}
	}
	
</script>
	
<style>
	.pages{
		height:100%;
		background-image: url(../../static/cut/loginBG.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
	}
	.status_bar {
	  height: var(--status-bar-height);
	  width: 100%;
	  background:#FFFFFF;
	}
	.title{
		height:98upx;
		text-align: center;
		font-size:36upx;
		line-height:98upx;
		color: #333333;
		position:relative;
	}
	.title .right{color:#b5b5b5;font-size:30upx;position:absolute;right:20upx;top:0;}
	.content{margin-top:120upx;}
	.input_row{display: flex;margin:0 45upx;border-bottom:1px solid #f1f1f1;padding:30upx 0;}
	.input_row image{width: 40upx;height: 40upx;margin-right:44upx;margin-left:15upx;}
	.input_row input{width:100%;font-size:30upx;}
	.input_row .showPassWord{width:40upx;height:24upx;margin-top:16rpx;margin-left:20upx;}
	.forget{margin-top:26px;margin:26upx 45upx 115upx;font-size:30upx;color:#b5b5b5;display: flex;}
	.forget text{margin-left: auto;}
	.forget radio-group, checkbox-group{width: calc(100% - 200rpx);}
	.loginHT{width:148upx;height:160upx;display: block;margin: 0 auto;}
	.btnLogin{width:508upx;height:88upx;margin:48upx auto 57upx;line-height:88upx;color: #FFFFFF;font-size:36upx;border-radius:44upx;background:#288bfe;}
	.otherLogin{display: flex;justify-content:center;}
	.otherLogin view{text-align: center;}
	.otherLogin view:first-child{margin-right:50upx;}
	.otherLogin view image{display: block;width:68upx;height:68upx;margin: 0 auto 29upx;}
	.otherLogin view text{font-size:22upx;color: #b5b5b5;display: inline-block;}
</style>
